<template>
  <a-card :bordered='false'>
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>

          <a-col :md='6' :sm='12'>
            <a-form-item label='货品类型名称'>
              <a-input placeholder='请输入货品类型名称查询' v-model='queryParam.name'></a-input>
            </a-form-item>
          </a-col>

          <a-col :md='6' :sm='8'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class='table-operator' style='border-top: 5px'>
      <a-button @click='handleAdd' type='primary' icon='plus'>添加货品类型</a-button>
      <a-button type='primary' icon='download' :loading='downloadLoading' @click="handleExportXls('货品信息')">导出</a-button>
      <a-dropdown v-if='selectedRowKeys.length > 0'>
        <a-menu slot='overlay' @click='handleMenuClick'>
          <a-menu-item key='1'>
            <a-icon type='delete' @click='batchDel' />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style='margin-left: 8px'>
          批量操作
          <a-icon type='down' />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
        <i class='anticon anticon-info-circle ant-alert-icon'></i>已选择&nbsp;<a style='font-weight: 600'>{{
          selectedRowKeys.length
        }}</a>项&nbsp;&nbsp;
        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>
      </div>

      <a-table
        ref='table'
        bordered
        size='middle'
        rowKey='id'
        :scroll='{ x: 2000 }'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        @change='handleTableChange'>

        <span slot='tags' slot-scope='text, record'>
                 <a-tag color='geekblue'>
                  {{ handlerTags(text) }}
                 </a-tag>
          </span>


        <span slot='action' slot-scope='text, record'>
          <a @click='handleEdit(record)'>编辑</a>
                    <a-divider type='vertical' />

          <a-dropdown>
            <a class='ant-dropdown-link'>
              更多 <a-icon type='down' />
            </a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <part-type-model ref='modalForm' @ok='modalFormOk'></part-type-model>

  </a-card>
</template>

<script>
import { ListMixin } from '@/mixins/ListMixin'
import PartTypeModel from './modules/PartTypeModel'


  export default {
    name: 'MotorPartType',
    mixins: [ListMixin],
    components: {
      PartTypeModel
    },
    data() {
      return {
        description: '这是货品类型页面',
        queryParam: {},
        columns: [
          {
            title: '名称',
            align: 'center',
            dataIndex: 'name',
            width: 260,
            sorter: true,
            fixed: true
          },
          {
            title: '货品类型编号',
            align: 'center',
            width: 180,
            dataIndex: 'partType'
          },
          {
            title: '录入时间',
            align: 'center',
            dataIndex: 'createTime'
          },
          {
            title: '操作',
            scopedSlots: { customRender: 'action' },
            align: 'center',
            fixed: 'right',
            width: 170
          }

        ],
        url: {
          list: '/motorfactory/part-type/list',
          delete: '/motorfactory/part-type/delete',
          deleteBatch: '/motorfactory/part-type/deleteBatch',
        }
      }
    },
    computed: {
    },
    methods: {
      handleMenuClick(e) {
        if (e.key == 1) {
          this.batchDel()
        } else if (e.key == 2) {
          this.batchFrozen(2)
        } else if (e.key == 3) {
          this.batchFrozen(1)
        }
      }
    }

  }
</script>